package com.example.campuslink.commen.adpter

import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterInvitationImageBinding
import com.example.campuslink.viewModel.InvitationDetailViewModel

class InvitationImageAdapter(vm: InvitationDetailViewModel) :
    CoreAdapter<AdapterInvitationImageBinding, InvitationDetailViewModel, String>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_invitation_image
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        Glide.with(holder.itemView.context).load(mListData[position])
            .error(R.drawable.ic_empty)
            .into(holder.binding.root.findViewById<ImageView>(R.id.iv_mainImg))
        if (mListData[position].contains(".mp4")) {
            holder.binding.root.findViewById<ImageView>(R.id.iv_play).visibility = View.VISIBLE
            holder.binding.root.setOnClickListener({
                mViewModel?.jumpToVideoPlay(mListData[position])
            })
        }
        if (position == 0) {
            holder.binding.root.findViewById<ImageView>(R.id.iv_toLeft).visibility = View.GONE
        } else {
            holder.binding.root.findViewById<ImageView>(R.id.iv_toLeft).visibility = View.VISIBLE
        }
        if (position == mListData.size - 1) {
            holder.binding.root.findViewById<ImageView>(R.id.iv_toRight).visibility = View.GONE
        } else {
            holder.binding.root.findViewById<ImageView>(R.id.iv_toRight).visibility = View.VISIBLE
        }
    }
}